import { createRouter, createWebHistory } from 'vue-router'
import ProblemListView from '../views/ProblemListView.vue'
import ProblemDetailView from '../views/ProblemDetailView.vue'
import FavoriteList from '../components/FavoriteList.vue'



const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/problems'
    },
    {
      path: '/problems',
      name: 'ProblemList',
      component: ProblemListView
    },
    {
      path: '/problem/:id',
      name: 'ProblemDetail',
      component: ProblemDetailView,
      props: true
    },
    {
      path: '/login',
      name: 'LoginPage',
      component: () => import('../views/LoginPage.vue')
    },
    {
      path: '/profile',
      name: 'Profile',
      component: () => import('../views/ProfilePage.vue'),
      meta: { requiresAuth: true }
    },
    {
      path: '/favorites',
      name: 'favorites',
      component: FavoriteList,
      meta: {
        requiresAuth: true
      }
    },
    // Admin routes
    {
      path: '/admin',
      component: () => import('../components/admin/AdminLayout.vue'),
      children: [
        {
          path: 'problems',
          name: 'AdminProblems',
          component: () => import('../components/admin/ProblemManagement.vue'),
          meta: { 
            requiresAuth: true,
            title: '题目管理'
          }
        },
        {
          path: 'users',
          name: 'AdminUsers',
          component: () => import('../components/admin/UserManagement.vue'),
          meta: { 
            requiresAuth: true,
            title: '用户管理'
          }
        }
      ]
    }
  ]
})

export default router
